using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class app_frame_documents : System.Web.UI.Page
{
    string strPagesetRowId = "5f4649e689509dea";
    DataSet dseInputInfo = new DataSet();
    DataSet dsePageInfo = new DataSet();
    HtmlForm frmObj;
    string strErrMessage = "";
    string refererURL = "";
    string dtFormat = "MM-dd-yyyy HH:mm:ss";
    //protected void Page_Error(object sender, EventArgs e)
    //{
    //    Response.Redirect("documents.aspx");
    //}
    protected void Page_Load(object sender, EventArgs e)
    {
        //if (!IsPostBack) Label1.Visible = false;
        if (Request.QueryString != null)
        {
            if (Request.QueryString["file"] != null)
            {
                giveFile();
                Response.End();
                return;
            }
        }
        //Navigator.validLogin("");
        lblStatusUpload.Text = "";
        //if (!IsPostBack) setFonts();
        //if (!IsPostBack) this.Error += new System.EventHandler(this.Page_Error);
        security hdds = new security();
        if (Session["userid"] == null) Response.Redirect(hdds.SessionExpiryURL);
        if (Session["userid"].ToString() == "") Response.Redirect(hdds.SessionExpiryURL);

        //Code added by Sampath on 18-Nov-2011 for IPP Vertical privilege
        if (Request.QueryString["mn"] != null)
        {
            if (!hdds.checkObjectMenuAccess(Request.QueryString["mn"]))
            {
                lbl_message.Text = wrapItAsMessage("<img src=\"Images/info.gif\" alt=\"\"></img>&nbsp;You do not have sufficient access permission.", true);
                tblcontrols.Visible = false;
                tblmain.Visible = false;
                tblbtn.Visible = false;
                return;
            }
        }

        //Code added by Sampath on 15-Nov-2011 for IPP Vertical privilege
        if (Request.QueryString["PK"] != null && Request.QueryString["pgs_id"] != null)
        {
            if (!hdds.checkRecordAccess(Request.QueryString["PK"].ToString(), Request.QueryString["pgs_id"].ToString()))
            {
                lbl_message.Text = wrapItAsMessage("<img src=\"Images/info.gif\" alt=\"\"></img>&nbsp;You do not have sufficient access permission.", true);
                tblcontrols.Visible = false;
                tblmain.Visible = false;
                tblbtn.Visible = false;
                return;
            }
        }


        setRequestURL();
        if (this.Master.FindControl("Form1") != null)
        {
            frmObj = (HtmlForm)this.Master.FindControl("Form1");
        }
        PageInfoLoad PIL = new PageInfoLoad();
        dsePageInfo = PIL.GetPageSetPageCtrlInfo(strPagesetRowId);

        if (!Page.IsPostBack)
        {
            loadOwneridDropDown();
        }

        CheckForChangeOwner();

        CheckEditOperation();
        addValidator();
        if (IsPostBack) return;
           
        if (btnUpdate.Visible)
        {
            lblHeader.Text = "Documents - Edit";
            loadMasterValues(false);
        }
        if (Request.QueryString["CPY"] != null)
        {
            if (Request.QueryString["CPY"] == "0")
            {
                lblHeader.Text = "Documents - Copy";
                loadMasterValues(true);
                //p_documents_owner_id_dd.SelectedValue = Session["user_afrowid"].ToString();
                p_documents_owner_id.Value = Session["user_afrowid"].ToString();
                txt_p_documents_owner_id.Text = Session["userid"].ToString();
                //loadChildValues();
                //showParamterContent(true, Request.QueryString["PK"].ToString());
                //p_format_masks_name.Text = getSeqNumber();
            }
        }

        getpageicons(); // Added by srivatsan
        isViewMode();
    }
    private void isViewMode()
    {
        if (HttpContext.Current.Request.QueryString["VMODE"] != null)
            if (HttpContext.Current.Request.QueryString["VMODE"] == "1")
            {
                lblHeader.Text = "Documents - View";
                DynamicDisplayI ddi = new DynamicDisplayI();
                HtmlTable ht = (HtmlTable)frmObj.FindControl("ContentPlaceHolder3").FindControl("TABLE1");
                ddi.disableControls(ht);
                ddi = null;
            }
    }    
    private void addValidator()
    {
        try
        {
            if (IsPostBack) return;
            if (Request.QueryString["PK"] != null && Request.QueryString["CPY"]==null)
                return;
            //if (Request.QueryString["CPY"] != null)
            //    return;
            lblMandatory.Text = "<img src=\"Images/star.gif\" alt=\"Required Field\"></img>";
            lblMandatory.Visible = true;
            RequiredFieldValidator2.Enabled = true;
       }
        catch (Exception e)
        {
            LogWriter.WriteLog("Error in addMandatoryValidator: " + e.Message);
        }
    }
    //private void setFonts()
    //{
    //    lblDetailsCaption.Font.Name = "Arial";
    //    lblDetailsCaption.Font.Size = FontUnit.Smaller;
    //    lblDetailsText.Font.Name = "Arial";
    //    lblDetailsText.Font.Size = FontUnit.Smaller;
    //    Label1.Font.Name = "Arial";
    //    Label1.Font.Size = FontUnit.Smaller;  
    //}
    private void giveFile()
    {
        SqlCommand cmd = new SqlCommand();
        HDDatabase hdd = new HDDatabase();
        try
        {
            string sql = "SELECT * FROM sy_documents where af_row_id='" + Request.QueryString["file"].ToString() + "'";
            cmd = new SqlCommand(sql);
            cmd.Connection = hdd.GetConnection();
            cmd.Connection.Open();
            SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.Default);
            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    //Response.BinaryWrite((byte[])reader["fileContent"]);
                    //string ss = reader["file_name"].ToString();
                    Response.Clear();
                    Response.Buffer = true;
                    //Response.ContentType = "multipart/mixed";
                    Response.ContentType = "application/x-download";
                    Response.AddHeader("content-disposition", "attachment;filename=\"" + reader["file_name"].ToString() + "\"");
                    //Response.Cache.SetCacheability(HttpCacheability.NoCache);
                    //Response.BinaryWrite((byte[])reader["content"]);
                    Response.OutputStream.Write((byte[])reader["fileContent"], 0, (int)reader["file_size"]);
                }
            }   
            #region alternate way
            //DataTable dt =  hdd.GetDataTable(sql);
            //byte[] cont = (byte[]) dt.Rows[0]["fileContent"];
            //Response.Clear();
            //Response.Buffer = true;
            //Response.ContentType = "multipart/mixed";
            //Response.AddHeader("content-disposition", "attachment;filename=" + dt.Rows[0]["file_name"].ToString());
            ////Response.Cache.SetCacheability(HttpCacheability.NoCache);
            ////Response.BinaryWrite((byte[])reader["content"]);
            //Response.OutputStream.Write(cont, 0, (int)dt.Rows[0]["file_size"]);
            //dt = null;
#endregion
        }
        catch (Exception e)
        {
            LogWriter.WriteLog("Error in giveFile function. Error: " + e.Message);
        }
        finally
        {
            hdd = null;
            if (cmd.Connection!=null)
                if (cmd.Connection.State == ConnectionState.Open) 
                    cmd.Connection.Close();
        }
    }
    private void setRequestURL()//implemented by sanal on 13 Dec 2007
    {
        if (!IsPostBack)
            //hfRequestURL.Value = Request.UrlReferrer.ToString();
            hfRequestURL.Value = "DisplayGrid.aspx?pgs_id=" + Request.QueryString["pgs_id"].ToString() + "&mn=" + Request.QueryString["mn"].ToString();
    }   
    private void loadMasterValues(bool copyMode)
    {
        try
        {
            string sPageKey = "";
            if (Request.QueryString["PK"] != null)
                sPageKey = Request.QueryString["PK"].ToString();
            if (sPageKey == "") return;
            HDDatabase hd = new HDDatabase();
            DataSet ds = new DataSet();
            ds = hd.GetDataset("select name,description,file_type,file_size,file_name,download_url,af_row_id,related_af_row_id,created_by,owner_id,created_at,modified_by,modified_at from sy_documents where af_row_id='" + sPageKey + "'");//no content should be retrieved
            
            if (ds.Tables.Count > 0)
            {
                if (ds.Tables[0].Rows.Count > 0)
                {
                    p_documents_af_row_id.Value = sPageKey;
                    p_documents_name.Text = ds.Tables[0].Rows[0]["name"].ToString();
                    p_documents_description.Text = ds.Tables[0].Rows[0]["description"].ToString();
                    if (!copyMode)
                    {
                        p_documents_download_url.Value = ds.Tables[0].Rows[0]["download_url"].ToString();
                        p_documents_file_name.Value = ds.Tables[0].Rows[0]["file_name"].ToString();
                        p_documents_file_size.Value = ds.Tables[0].Rows[0]["file_size"].ToString();
                        p_documents_file_type.Value = ds.Tables[0].Rows[0]["file_type"].ToString(); //Added by 'Imran Gani' on 14Sep12 to get the file type.
                        p_documents_related_af_row_id.Value = ds.Tables[0].Rows[0]["related_af_row_id"].ToString();
                        lblDetailsCaption.Text = "&nbsp;Uploaded File";
                        lblDetailsCaption.Visible = true;
                        lblDetailsText.Text = ds.Tables[0].Rows[0]["download_url"].ToString();// "<a href='" + ds.Tables[0].Rows[0]["download_url"].ToString() + "'>" + ds.Tables[0].Rows[0]["file_name"].ToString() + "</a>";
                        lblDetailsText.Visible = true;
                        //p_documents_owner_id_dd.SelectedValue = ds.Tables[0].Rows[0]["owner_id"].ToString();
                        p_documents_owner_id.Value = ds.Tables[0].Rows[0]["owner_id"].ToString();
                        LoadEditPage LEP = new LoadEditPage();
                        txt_p_documents_owner_id.Text = LEP.GetUserIDFromAfrowid(ds.Tables[0].Rows[0]["owner_id"].ToString());
                        LEP = null;
                    }
                    if (!copyMode)
                        Label1.Text = "<br><img src='Images/warning_small.gif'></img>&nbsp;Currently uploaded file will get replaced with the new file specified, if " + (copyMode == true ? "saved." : "updated.");
                    else
                        Label1.Text = "<br><img src='Images/warning_small.gif'></img>&nbsp;Copying of the same document is not allowed. Please upload a document.";
                     Label1.Visible = true;
                }
            }

            ds = null;
            hd = null;
        }
        catch (Exception e)
        {
            LogWriter.WriteLog("Error in messages.aspx:loadMasterValues: " + e.Message);
        }
    }
    private string getDateTimeValue(string inp)
    {
        try
        {
            DynamicDisplayI DDI = new DynamicDisplayI();
            string sTemp = DDI.getUsersDateTime(inp);
            if (sTemp == "") sTemp = inp;
            DateTime dt = DateTime.Parse(sTemp);
            return dt.ToString("MM-dd-yyyy HH:mm:ss");
        }
        catch (Exception e)
        {
            return inp;
        }
    }
    private void loadDynamicControls()
    {
        //if (IsPostBack) return;
        HiddenField hf = new HiddenField();
        hf.ID = "hf_ref_url";
        hf.EnableViewState = true;
        if (refererURL.Length > 0) hf.Value = refererURL;
        lbl_message.Controls.Add(hf);
    }

    private void loadRecurrTypes()
    {
        
    }
    private void loadCategory()
    {
        
    }
    private bool CheckEditOperation()
    {
        bool blnStatus = true;
        string strPageKey = "";
        bool IsEdit = false;
        if (Page.IsPostBack == false)
        {
            if (Request.QueryString["PK"] != null)
            {
                strPageKey = Request.QueryString["PK"].ToString();
                IsEdit = true;
            }
            if (IsEdit)
            {
                Master MA = new Master();
                blnStatus = MA.EditOperation(dsePageInfo, frmObj, strPageKey);
                if (blnStatus == false)
                {
                    strErrMessage = MA.ErrorMessage;
                    Response.Write("<font color='red'>Error : " + strErrMessage + "</font>");
                }
            }
        }
        if (Request.QueryString["CPY"] != null)
        {
            if (Request.QueryString["CPY"] == "0")
            {
                btnSave.Visible = true;
                btnUpdate.Visible = false;
            }
        }
        else if (Request.QueryString["PK"] == null)
        {
            btnSave.Visible = true;
            btnUpdate.Visible = false;
        }
        else
        {
            btnUpdate.Visible = true;
            btnSave.Visible = false;
        }
        return blnStatus;
    }



    private bool SaveData()
    {
        bool blnStatus = true;
        ScreenReader SR = new ScreenReader();
        dseInputInfo = SR.CaptureData(strPagesetRowId, frmObj, dsePageInfo,true);
        if (SR.errormessage!="")
        {
            strErrMessage = SR.errormessage;
            return false;
        }



        p_documents_af_row_id.Value = dseInputInfo.Tables[0].Rows[0]["af_row_id"].ToString();
        Master MA = new Master();
        blnStatus = MA.ProcessOperation(dsePageInfo, dseInputInfo, "INSERT");
        if (blnStatus == false)
        {
            strErrMessage = MA.ErrorMessage;
        }
        return blnStatus;
    }

    private bool UpdateData()
    {
        bool blnStatus = true;
        ScreenReader SR = new ScreenReader();
        dseInputInfo = SR.CaptureData(strPagesetRowId, frmObj, dsePageInfo,false);
        if (SR.errormessage != "")
        {
            strErrMessage = SR.errormessage;
            return false;
        }
        Master MA = new Master();
        blnStatus = MA.ProcessOperation(dsePageInfo, dseInputInfo, "UPDATE");
        if (blnStatus == false)
        {
            strErrMessage = MA.ErrorMessage;
        }
        return blnStatus;
    }

    protected void Page_PreInit(object sender, EventArgs e)
    {
        this.Theme = Session["Theme"].ToString();
        this.Title = "MaxBlox";
    }
    private bool isInteger(string inp)
    {
        if (inp.Trim().Length == 0) return false;
        try
        {
            int i = Convert.ToInt32(inp);
            return true;
        }
        catch (Exception e)
        {
            return false;
        }
    }
    private bool isDateTime(string inp)
    {
        if (inp.Trim().Length == 0) return false;
        try
        {
            //30-11-2007 13:53:13
            //DateTime dt = DateTime.Parse(inp);
            DateTime dt = DateTime.ParseExact(inp,dtFormat, null);
            return true;
        }
        catch (Exception e)
        {
            return false;
        }
    }
    private bool validate()
    {
        try
        {
            //string ret = p_job_schedules_jb_sch_id.Text;            
            return true;
        }
        catch (Exception e)
        {
            return false;
        }
    }
    private bool validFile()
    {
        string ext = System.IO.Path.GetExtension(FileUpload1.PostedFile.FileName).ToLower();        
        string[] invalids = new string[] {".exe",".dll",".ocx",".bat" };
        for (int i = 0; i < invalids.Length; i++)
        {
            if (ext.IndexOf(invalids[i]) > -1)
                return false;
        }
        return true;

    }
    private string uploadFile(bool updateMode)
    {
        try
        {
            string sMasterKey = ""; // Added by 'Imran Gani' on Sep 18 2012 for Documents changes
            if (Request.QueryString["Mk"] != null)
                sMasterKey = Request.QueryString["Mk"].ToString();
            else
                sMasterKey = p_documents_related_af_row_id.Value;
            
            if (FileUpload1.HasFile)
            {
                if (FileUpload1.FileName.Length > 0)
                {
                    int len = FileUpload1.PostedFile.ContentLength;
                    //if (len > 5242880) return "Exceeded the file size limit.";
                    if (len > 4096000) return "Exceeded the file size limit.";
                    byte[] filea = new byte[len];
                    FileUpload1.PostedFile.InputStream.Read(filea, 0, len);

                    //string sql = "insert into testUpload (name, filename,content) values ('test','" + FileUpload1.PostedFile.FileName + "',@pcont" + ")";
                    string sql = "update sy_documents set fileContent=@pcont, file_type='" + getMimeType(System.IO.Path.GetExtension(FileUpload1.PostedFile.FileName)).Replace("'","''") + "', file_size=" + len.ToString()
                                    + ", file_name='" + System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName).Replace("'","''")
                                    + "', download_url='<a href=''documents.aspx?file=" + p_documents_af_row_id.Value + "''>" + System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName).Replace("'","''") + "</a>' " +
                                    ", related_af_row_id='" + sMasterKey + "' " + // Added by 'Imran Gani' on Sep 18 2012 for Documents changes
                                "where af_row_id='" + p_documents_af_row_id.Value + "'";//changed by sanal on 25Mar09 for file_type

                    SqlCommand sc = new SqlCommand(sql);
                    SqlParameter sp = new SqlParameter("@pcont", SqlDbType.VarBinary, len);
                    FileUpload1.PostedFile.InputStream.Close();
                    sp.Value = filea;
                    sc.Parameters.Add(sp);
                    HDDatabase hdd = new HDDatabase();
                    hdd.ExecuteCmdObj(sc);
                    hdd = null;
                }
                return "";
            }
            else
            {
                if (updateMode)
                {   //Added by 'Imran Gani' on 14Sep12 to save the same file.
                    string sql = "update sy_documents set file_type='" + p_documents_file_type.Value.Replace("'", "''") + "', download_url='<a href=''documents.aspx?file=" + p_documents_af_row_id.Value + "''>" + p_documents_file_name.Value.Replace("'", "''") + "</a>', related_af_row_id='" + sMasterKey + "' " +
                                "where af_row_id='" + p_documents_af_row_id.Value + "'";
                    SqlCommand sc = new SqlCommand(sql);
                    HDDatabase hdd = new HDDatabase();
                    hdd.ExecuteCmdObj(sc);
                    hdd = null;
                    return "";
                }
                else
                {
                    //delete the record
                    string sqql = "delete from sy_documents where af_row_id='" + p_documents_af_row_id.Value + "'";
                    HDDatabase hdd = new HDDatabase();
                    hdd.ExecuteCmdObj(new SqlCommand(sqql));
                    p_documents_af_row_id.Value = "";
                    hdd = null;
                    return "No File specified to upload.";
                }
            }
        }
        catch (Exception e)
        {
            return e.Message;
        }
    }
    private string wrapItAsMessage(string msg, bool isError)
    {
        return "<div class=\"" + (isError == true ? "mbErrorMessage" : "mbMessage") + "\">" + msg + "</div>";
    }
    protected void btnSave_ServerClick(object sender, EventArgs e)
    {
        //lbl_message.Text = "sanal";
        //return;         
        //string ret = p_help_help_desc.Text;   
        //if (!validate()) return;
        if (!validFile())
        {
            lbl_message.Text = wrapItAsMessage("<img src=\"Images/error.gif\" alt=\"Error\"></img>&nbsp;" + "Invalid File specified.",true) ;
            return;
        }
        if (SaveData())
        {
            string ret = uploadFile(false);
            if (ret!="")
            {
                lbl_message.Text = wrapItAsMessage("Error occurred during upload. Error: " + ret, true);
                return;
            }

            //Response.Write("Data Inserted Successfully");
            string refURL = getRefURL();
            if (refURL.Length > 0)
                Response.Redirect(refURL);
            else
                lbl_message.Text = wrapItAsMessage("Data Inserted Successfully",false);
        }
        else
        {
            lbl_message.Text = wrapItAsMessage("<img src=\"Images/error.gif\" alt=\"Error\"></img>&nbsp;" + "Data Insert not successful. Error:" + HttpUtility.HtmlEncode(ErrorMessage),true);
        }
    }
    protected void btnUpdate_ServerClick(object sender, EventArgs e)
    {
        //if (!validate()) return;
        if (!validFile())
        {
            lbl_message.Text = wrapItAsMessage("<img src=\"Images/error.gif\" alt=\"Error\"></img>&nbsp;" + "Invalid File specified.", true);
            return;
        }
        if (UpdateData())
        {
            string ret = uploadFile(true);
            if (ret != "")
            {
                lbl_message.Text = wrapItAsMessage("Error occurred during upload. Error: " + ret,true);
                return;
            }
            string refURL = getRefURL();
            if (refURL.Length > 0)
                Response.Redirect(refURL);
            else
                lbl_message.Text = wrapItAsMessage("Data Updated Successfully", false);
        }
        else
        {
            lbl_message.Text = wrapItAsMessage("<img src=\"Images/error.gif\" alt=\"Error\"></img>&nbsp;" + "Data Update not successful. Error:" + HttpUtility.HtmlEncode(ErrorMessage),true);
        }
    }

    protected void btnreset_ServerClick(object sender, EventArgs e)
    {
        //Response.Redirect(Request.RawUrl);
        try
        {
            //if (p_format_masks_type.Items.Count>0)   p_format_masks_type.SelectedIndex = 0;
            
        }
        catch (Exception ee)
        {

        }
    }
    private string getRefURL()
    {
        string ret = "";
        try
        {
            //return hfRequestURL.Value;
            if (HttpContext.Current.Session["URLs"] == null)
                return hfRequestURL.Value;
            else
            {
                return Navigator.getURL(Request.Url.ToString());
            }
            //DynamicDisplayI di = new DynamicDisplayI();
            //HiddenField hf = (HiddenField)di.FindControl(this.Controls, "hf_ref_url");
            //ret = hf.Value;
            //di = null;
            //return ret;
        }
        catch (Exception e)
        {
            return "";
        }

    }
    
    public string ErrorMessage
    {
        get
        {
            return this.strErrMessage;
        }
    }
    private void getpageicons() // Added by srivatsan to get page icons
    {
        PageIcons icons = new PageIcons();
        HDDatabase Hdd = new HDDatabase();
        try
        {
            string strPagesetRowID = Request.QueryString["pgs_id"].ToString();

            lblHeader.Text = "&nbsp;" + icons.geticontextfrompageset(strPagesetRowID, 2) + "&nbsp;" + lblHeader.Text;
        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("Error :getpageicons() " + ex.Message);
            lblHeader.Text = "<img src=Images/MBIcons/small/default.png></img>&nbsp;" + lblHeader.Text;
        }
        finally
        {
            icons = null;
            Hdd = null;
        }

    }
    private string getMimeType(string fileExtension)//included by sanal on 25Mar09 for file_type/mime type
    {
        string retval = "";
        //switch (Systm.IO.Path.GetExtension(strFileName).ToLower())
        switch (fileExtension.ToLower())
        {
            case ".3dm": retval = "x-world/x-3dmf"; break;
            case ".3dmf": retval = "x-world/x-3dmf"; break;
            case ".a": retval = "application/octet-stream"; break;
            case ".aab": retval = "application/x-authorware-bin"; break;
            case ".aam": retval = "application/x-authorware-map"; break;
            case ".aas": retval = "application/x-authorware-seg"; break;
            case ".abc": retval = "text/vnd.abc"; break;
            case ".acgi": retval = "text/html"; break;
            case ".afl": retval = "video/animaflex"; break;
            case ".ai": retval = "application/postscript"; break;
            case ".aif": retval = "audio/aiff"; break;
            case ".aifc": retval = "audio/aiff"; break;
            case ".aiff": retval = "audio/aiff"; break;
            case ".aim": retval = "application/x-aim"; break;
            case ".aip": retval = "text/x-audiosoft-intra"; break;
            case ".ani": retval = "application/x-navi-animation"; break;
            case ".aos": retval = "application/x-nokia-9000-communicator-add-on-software"; break;
            case ".aps": retval = "application/mime"; break;
            case ".arc": retval = "application/octet-stream"; break;
            case ".arj": retval = "application/arj"; break;
            case ".art": retval = "image/x-jg"; break;
            case ".asf": retval = "video/x-ms-asf"; break;
            case ".asm": retval = "text/x-asm"; break;
            case ".asp": retval = "text/asp"; break;
            case ".asx": retval = "video/x-ms-asf"; break;
            case ".au": retval = "audio/basic"; break;
            case ".avi": retval = "video/avi"; break;
            case ".avs": retval = "video/avs-video"; break;
            case ".bcpio": retval = "application/x-bcpio"; break;
            case ".bin": retval = "application/octet-stream"; break;
            case ".bm": retval = "image/bmp"; break;
            case ".bmp": retval = "image/bmp"; break;
            case ".boo": retval = "application/book"; break;
            case ".book": retval = "application/book"; break;
            case ".boz": retval = "application/x-bzip2"; break;
            case ".bsh": retval = "application/x-bsh"; break;
            case ".bz": retval = "application/x-bzip"; break;
            case ".bz2": retval = "application/x-bzip2"; break;
            case ".c": retval = "text/plain"; break;
            case ".c++": retval = "text/plain"; break;
            case ".cat": retval = "application/vnd.ms-pki.seccat"; break;
            case ".cc": retval = "text/plain"; break;
            case ".ccad": retval = "application/clariscad"; break;
            case ".cco": retval = "application/x-cocoa"; break;
            case ".cdf": retval = "application/cdf"; break;
            case ".cer": retval = "application/pkix-cert"; break;
            case ".cha": retval = "application/x-chat"; break;
            case ".chat": retval = "application/x-chat"; break;
            case ".class": retval = "application/java"; break;
            case ".com": retval = "application/octet-stream"; break;
            case ".conf": retval = "text/plain"; break;
            case ".cpio": retval = "application/x-cpio"; break;
            case ".cpp": retval = "text/x-c"; break;
            case ".cpt": retval = "application/x-cpt"; break;
            case ".crl": retval = "application/pkcs-crl"; break;
            case ".crt": retval = "application/pkix-cert"; break;
            case ".csh": retval = "application/x-csh"; break;
            case ".css": retval = "text/css"; break;
            case ".cxx": retval = "text/plain"; break;
            case ".dcr": retval = "application/x-director"; break;
            case ".deepv": retval = "application/x-deepv"; break;
            case ".def": retval = "text/plain"; break;
            case ".der": retval = "application/x-x509-ca-cert"; break;
            case ".dif": retval = "video/x-dv"; break;
            case ".dir": retval = "application/x-director"; break;
            case ".dl": retval = "video/dl"; break;
            case ".doc": retval = "application/msword"; break;
            case ".dot": retval = "application/msword"; break;
            case ".dp": retval = "application/commonground"; break;
            case ".drw": retval = "application/drafting"; break;
            case ".dump": retval = "application/octet-stream"; break;
            case ".dv": retval = "video/x-dv"; break;
            case ".dvi": retval = "application/x-dvi"; break;
            case ".dwf": retval = "model/vnd.dwf"; break;
            case ".dwg": retval = "image/vnd.dwg"; break;
            case ".dxf": retval = "image/vnd.dwg"; break;
            case ".dxr": retval = "application/x-director"; break;
            case ".el": retval = "text/x-script.elisp"; break;
            case ".elc": retval = "application/x-elc"; break;
            case ".env": retval = "application/x-envoy"; break;
            case ".eps": retval = "application/postscript"; break;
            case ".es": retval = "application/x-esrehber"; break;
            case ".etx": retval = "text/x-setext"; break;
            case ".evy": retval = "application/envoy"; break;
            case ".exe": retval = "application/octet-stream"; break;
            case ".f": retval = "text/plain"; break;
            case ".f77": retval = "text/x-fortran"; break;
            case ".f90": retval = "text/plain"; break;
            case ".fdf": retval = "application/vnd.fdf"; break;
            case ".fif": retval = "image/fif"; break;
            case ".fli": retval = "video/fli"; break;
            case ".flo": retval = "image/florian"; break;
            case ".flx": retval = "text/vnd.fmi.flexstor"; break;
            case ".fmf": retval = "video/x-atomic3d-feature"; break;
            case ".for": retval = "text/x-fortran"; break;
            case ".fpx": retval = "image/vnd.fpx"; break;
            case ".frl": retval = "application/freeloader"; break;
            case ".funk": retval = "audio/make"; break;
            case ".g": retval = "text/plain"; break;
            case ".g3": retval = "image/g3fax"; break;
            case ".gif": retval = "image/gif"; break;
            case ".gl": retval = "video/gl"; break;
            case ".gsd": retval = "audio/x-gsm"; break;
            case ".gsm": retval = "audio/x-gsm"; break;
            case ".gsp": retval = "application/x-gsp"; break;
            case ".gss": retval = "application/x-gss"; break;
            case ".gtar": retval = "application/x-gtar"; break;
            case ".gz": retval = "application/x-gzip"; break;
            case ".gzip": retval = "application/x-gzip"; break;
            case ".h": retval = "text/plain"; break;
            case ".hdf": retval = "application/x-hdf"; break;
            case ".help": retval = "application/x-helpfile"; break;
            case ".hgl": retval = "application/vnd.hp-hpgl"; break;
            case ".hh": retval = "text/plain"; break;
            case ".hlb": retval = "text/x-script"; break;
            case ".hlp": retval = "application/hlp"; break;
            case ".hpg": retval = "application/vnd.hp-hpgl"; break;
            case ".hpgl": retval = "application/vnd.hp-hpgl"; break;
            case ".hqx": retval = "application/binhex"; break;
            case ".hta": retval = "application/hta"; break;
            case ".htc": retval = "text/x-component"; break;
            case ".htm": retval = "text/html"; break;
            case ".html": retval = "text/html"; break;
            case ".htmls": retval = "text/html"; break;
            case ".htt": retval = "text/webviewhtml"; break;
            case ".htx": retval = "text/html"; break;
            case ".ice": retval = "x-conference/x-cooltalk"; break;
            case ".ico": retval = "image/x-icon"; break;
            case ".idc": retval = "text/plain"; break;
            case ".ief": retval = "image/ief"; break;
            case ".iefs": retval = "image/ief"; break;
            case ".iges": retval = "application/iges"; break;
            case ".igs": retval = "application/iges"; break;
            case ".ima": retval = "application/x-ima"; break;
            case ".imap": retval = "application/x-httpd-imap"; break;
            case ".inf": retval = "application/inf"; break;
            case ".ins": retval = "application/x-internett-signup"; break;
            case ".ip": retval = "application/x-ip2"; break;
            case ".isu": retval = "video/x-isvideo"; break;
            case ".it": retval = "audio/it"; break;
            case ".iv": retval = "application/x-inventor"; break;
            case ".ivr": retval = "i-world/i-vrml"; break;
            case ".ivy": retval = "application/x-livescreen"; break;
            case ".jam": retval = "audio/x-jam"; break;
            case ".jav": retval = "text/plain"; break;
            case ".java": retval = "text/plain"; break;
            case ".jcm": retval = "application/x-java-commerce"; break;
            case ".jfif": retval = "image/jpeg"; break;
            case ".jfif-tbnl": retval = "image/jpeg"; break;
            case ".jpe": retval = "image/jpeg"; break;
            case ".jpeg": retval = "image/jpeg"; break;
            case ".jpg": retval = "image/jpeg"; break;
            case ".jps": retval = "image/x-jps"; break;
            case ".js": retval = "application/x-javascript"; break;
            case ".jut": retval = "image/jutvision"; break;
            case ".kar": retval = "audio/midi"; break;
            case ".ksh": retval = "application/x-ksh"; break;
            case ".la": retval = "audio/nspaudio"; break;
            case ".lam": retval = "audio/x-liveaudio"; break;
            case ".latex": retval = "application/x-latex"; break;
            case ".lha": retval = "application/octet-stream"; break;
            case ".lhx": retval = "application/octet-stream"; break;
            case ".list": retval = "text/plain"; break;
            case ".lma": retval = "audio/nspaudio"; break;
            case ".log": retval = "text/plain"; break;
            case ".lsp": retval = "application/x-lisp"; break;
            case ".lst": retval = "text/plain"; break;
            case ".lsx": retval = "text/x-la-asf"; break;
            case ".ltx": retval = "application/x-latex"; break;
            case ".lzh": retval = "application/octet-stream"; break;
            case ".lzx": retval = "application/octet-stream"; break;
            case ".m": retval = "text/plain"; break;
            case ".m1v": retval = "video/mpeg"; break;
            case ".m2a": retval = "audio/mpeg"; break;
            case ".m2v": retval = "video/mpeg"; break;
            case ".m3u": retval = "audio/x-mpequrl"; break;
            case ".man": retval = "application/x-troff-man"; break;
            case ".map": retval = "application/x-navimap"; break;
            case ".mar": retval = "text/plain"; break;
            case ".mbd": retval = "application/mbedlet"; break;
            case ".mc$": retval = "application/x-magic-cap-package-1.0"; break;
            case ".mcd": retval = "application/mcad"; break;
            case ".mcf": retval = "text/mcf"; break;
            case ".mcp": retval = "application/netmc"; break;
            case ".me": retval = "application/x-troff-me"; break;
            case ".mht": retval = "message/rfc822"; break;
            case ".mhtml": retval = "message/rfc822"; break;
            case ".mid": retval = "audio/midi"; break;
            case ".midi": retval = "audio/midi"; break;
            case ".mif": retval = "application/x-mif"; break;
            case ".mime": retval = "message/rfc822"; break;
            case ".mjf": retval = "audio/x-vnd.audioexplosion.mjuicemediafile"; break;
            case ".mjpg": retval = "video/x-motion-jpeg"; break;
            case ".mm": retval = "application/base64"; break;
            case ".mme": retval = "application/base64"; break;
            case ".mod": retval = "audio/mod"; break;
            case ".moov": retval = "video/quicktime"; break;
            case ".mov": retval = "video/quicktime"; break;
            case ".movie": retval = "video/x-sgi-movie"; break;
            case ".mp2": retval = "audio/mpeg"; break;
            case ".mp3": retval = "audio/mpeg"; break;
            case ".mpa": retval = "audio/mpeg"; break;
            case ".mpc": retval = "application/x-project"; break;
            case ".mpe": retval = "video/mpeg"; break;
            case ".mpeg": retval = "video/mpeg"; break;
            case ".mpg": retval = "video/mpeg"; break;
            case ".mpga": retval = "audio/mpeg"; break;
            case ".mpp": retval = "application/vnd.ms-project"; break;
            case ".mpt": retval = "application/vnd.ms-project"; break;
            case ".mpv": retval = "application/vnd.ms-project"; break;
            case ".mpx": retval = "application/vnd.ms-project"; break;
            case ".mrc": retval = "application/marc"; break;
            case ".ms": retval = "application/x-troff-ms"; break;
            case ".mv": retval = "video/x-sgi-movie"; break;
            case ".my": retval = "audio/make"; break;
            case ".mzz": retval = "application/x-vnd.audioexplosion.mzz"; break;
            case ".nap": retval = "image/naplps"; break;
            case ".naplps": retval = "image/naplps"; break;
            case ".nc": retval = "application/x-netcdf"; break;
            case ".ncm": retval = "application/vnd.nokia.configuration-message"; break;
            case ".nif": retval = "image/x-niff"; break;
            case ".niff": retval = "image/x-niff"; break;
            case ".nix": retval = "application/x-mix-transfer"; break;
            case ".nsc": retval = "application/x-conference"; break;
            case ".nvd": retval = "application/x-navidoc"; break;
            case ".o": retval = "application/octet-stream"; break;
            case ".oda": retval = "application/oda"; break;
            case ".omc": retval = "application/x-omc"; break;
            case ".omcd": retval = "application/x-omcdatamaker"; break;
            case ".omcr": retval = "application/x-omcregerator"; break;
            case ".p": retval = "text/x-pascal"; break;
            case ".p10": retval = "application/pkcs10"; break;
            case ".p12": retval = "application/pkcs-12"; break;
            case ".p7a": retval = "application/x-pkcs7-signature"; break;
            case ".p7c": retval = "application/pkcs7-mime"; break;
            case ".p7m": retval = "application/pkcs7-mime"; break;
            case ".p7r": retval = "application/x-pkcs7-certreqresp"; break;
            case ".p7s": retval = "application/pkcs7-signature"; break;
            case ".part": retval = "application/pro_eng"; break;
            case ".pas": retval = "text/pascal"; break;
            case ".pbm": retval = "image/x-portable-bitmap"; break;
            case ".pcl": retval = "application/vnd.hp-pcl"; break;
            case ".pct": retval = "image/x-pict"; break;
            case ".pcx": retval = "image/x-pcx"; break;
            case ".pdb": retval = "chemical/x-pdb"; break;
            case ".pdf": retval = "application/pdf"; break;
            case ".pfunk": retval = "audio/make"; break;
            case ".pgm": retval = "image/x-portable-greymap"; break;
            case ".pic": retval = "image/pict"; break;
            case ".pict": retval = "image/pict"; break;
            case ".pkg": retval = "application/x-newton-compatible-pkg"; break;
            case ".pko": retval = "application/vnd.ms-pki.pko"; break;
            case ".pl": retval = "text/plain"; break;
            case ".plx": retval = "application/x-pixclscript"; break;
            case ".pm": retval = "image/x-xpixmap"; break;
            case ".pm4": retval = "application/x-pagemaker"; break;
            case ".pm5": retval = "application/x-pagemaker"; break;
            case ".png": retval = "image/png"; break;
            case ".pnm": retval = "application/x-portable-anymap"; break;
            case ".pot": retval = "application/vnd.ms-powerpoint"; break;
            case ".pov": retval = "model/x-pov"; break;
            case ".ppa": retval = "application/vnd.ms-powerpoint"; break;
            case ".ppm": retval = "image/x-portable-pixmap"; break;
            case ".pps": retval = "application/vnd.ms-powerpoint"; break;
            case ".ppt": retval = "application/vnd.ms-powerpoint"; break;
            case ".ppz": retval = "application/vnd.ms-powerpoint"; break;
            case ".pre": retval = "application/x-freelance"; break;
            case ".prt": retval = "application/pro_eng"; break;
            case ".ps": retval = "application/postscript"; break;
            case ".psd": retval = "application/octet-stream"; break;
            case ".pvu": retval = "paleovu/x-pv"; break;
            case ".pwz": retval = "application/vnd.ms-powerpoint"; break;
            case ".py": retval = "text/x-script.phyton"; break;
            case ".pyc": retval = "applicaiton/x-bytecode.python"; break;
            case ".qcp": retval = "audio/vnd.qcelp"; break;
            case ".qd3": retval = "x-world/x-3dmf"; break;
            case ".qd3d": retval = "x-world/x-3dmf"; break;
            case ".qif": retval = "image/x-quicktime"; break;
            case ".qt": retval = "video/quicktime"; break;
            case ".qtc": retval = "video/x-qtc"; break;
            case ".qti": retval = "image/x-quicktime"; break;
            case ".qtif": retval = "image/x-quicktime"; break;
            case ".ra": retval = "audio/x-pn-realaudio"; break;
            case ".ram": retval = "audio/x-pn-realaudio"; break;
            case ".ras": retval = "application/x-cmu-raster"; break;
            case ".rast": retval = "image/cmu-raster"; break;
            case ".rexx": retval = "text/x-script.rexx"; break;
            case ".rf": retval = "image/vnd.rn-realflash"; break;
            case ".rgb": retval = "image/x-rgb"; break;
            case ".rm": retval = "application/vnd.rn-realmedia"; break;
            case ".rmi": retval = "audio/mid"; break;
            case ".rmm": retval = "audio/x-pn-realaudio"; break;
            case ".rmp": retval = "audio/x-pn-realaudio"; break;
            case ".rng": retval = "application/ringing-tones"; break;
            case ".rnx": retval = "application/vnd.rn-realplayer"; break;
            case ".roff": retval = "application/x-troff"; break;
            case ".rp": retval = "image/vnd.rn-realpix"; break;
            case ".rpm": retval = "audio/x-pn-realaudio-plugin"; break;
            case ".rt": retval = "text/richtext"; break;
            case ".rtf": retval = "text/richtext"; break;
            case ".rtx": retval = "text/richtext"; break;
            case ".rv": retval = "video/vnd.rn-realvideo"; break;
            case ".s": retval = "text/x-asm"; break;
            case ".s3m": retval = "audio/s3m"; break;
            case ".saveme": retval = "application/octet-stream"; break;
            case ".sbk": retval = "application/x-tbook"; break;
            case ".scm": retval = "application/x-lotusscreencam"; break;
            case ".sdml": retval = "text/plain"; break;
            case ".sdp": retval = "application/sdp"; break;
            case ".sdr": retval = "application/sounder"; break;
            case ".sea": retval = "application/sea"; break;
            case ".set": retval = "application/set"; break;
            case ".sgm": retval = "text/sgml"; break;
            case ".sgml": retval = "text/sgml"; break;
            case ".sh": retval = "application/x-sh"; break;
            case ".shar": retval = "application/x-shar"; break;
            case ".shtml": retval = "text/html"; break;
            case ".sid": retval = "audio/x-psid"; break;
            case ".sit": retval = "application/x-sit"; break;
            case ".skd": retval = "application/x-koan"; break;
            case ".skm": retval = "application/x-koan"; break;
            case ".skp": retval = "application/x-koan"; break;
            case ".skt": retval = "application/x-koan"; break;
            case ".sl": retval = "application/x-seelogo"; break;
            case ".smi": retval = "application/smil"; break;
            case ".smil": retval = "application/smil"; break;
            case ".snd": retval = "audio/basic"; break;
            case ".sol": retval = "application/solids"; break;
            case ".spc": retval = "text/x-speech"; break;
            case ".spl": retval = "application/futuresplash"; break;
            case ".spr": retval = "application/x-sprite"; break;
            case ".sprite": retval = "application/x-sprite"; break;
            case ".src": retval = "application/x-wais-source"; break;
            case ".ssi": retval = "text/x-server-parsed-html"; break;
            case ".ssm": retval = "application/streamingmedia"; break;
            case ".sst": retval = "application/vnd.ms-pki.certstore"; break;
            case ".step": retval = "application/step"; break;
            case ".stl": retval = "application/sla"; break;
            case ".stp": retval = "application/step"; break;
            case ".sv4cpio": retval = "application/x-sv4cpio"; break;
            case ".sv4crc": retval = "application/x-sv4crc"; break;
            case ".svf": retval = "image/vnd.dwg"; break;
            case ".svr": retval = "application/x-world"; break;
            case ".swf": retval = "application/x-shockwave-flash"; break;
            case ".t": retval = "application/x-troff"; break;
            case ".talk": retval = "text/x-speech"; break;
            case ".tar": retval = "application/x-tar"; break;
            case ".tbk": retval = "application/toolbook"; break;
            case ".tcl": retval = "application/x-tcl"; break;
            case ".tcsh": retval = "text/x-script.tcsh"; break;
            case ".tex": retval = "application/x-tex"; break;
            case ".texi": retval = "application/x-texinfo"; break;
            case ".texinfo": retval = "application/x-texinfo"; break;
            case ".text": retval = "text/plain"; break;
            case ".tgz": retval = "application/x-compressed"; break;
            case ".tif": retval = "image/tiff"; break;
            case ".tiff": retval = "image/tiff"; break;
            case ".tr": retval = "application/x-troff"; break;
            case ".tsi": retval = "audio/tsp-audio"; break;
            case ".tsp": retval = "application/dsptype"; break;
            case ".tsv": retval = "text/tab-separated-values"; break;
            case ".turbot": retval = "image/florian"; break;
            case ".txt": retval = "text/plain"; break;
            case ".uil": retval = "text/x-uil"; break;
            case ".uni": retval = "text/uri-list"; break;
            case ".unis": retval = "text/uri-list"; break;
            case ".unv": retval = "application/i-deas"; break;
            case ".uri": retval = "text/uri-list"; break;
            case ".uris": retval = "text/uri-list"; break;
            case ".ustar": retval = "application/x-ustar"; break;
            case ".uu": retval = "application/octet-stream"; break;
            case ".uue": retval = "text/x-uuencode"; break;
            case ".vcd": retval = "application/x-cdlink"; break;
            case ".vcs": retval = "text/x-vcalendar"; break;
            case ".vda": retval = "application/vda"; break;
            case ".vdo": retval = "video/vdo"; break;
            case ".vew": retval = "application/groupwise"; break;
            case ".viv": retval = "video/vivo"; break;
            case ".vivo": retval = "video/vivo"; break;
            case ".vmd": retval = "application/vocaltec-media-desc"; break;
            case ".vmf": retval = "application/vocaltec-media-file"; break;
            case ".voc": retval = "audio/voc"; break;
            case ".vos": retval = "video/vosaic"; break;
            case ".vox": retval = "audio/voxware"; break;
            case ".vqe": retval = "audio/x-twinvq-plugin"; break;
            case ".vqf": retval = "audio/x-twinvq"; break;
            case ".vql": retval = "audio/x-twinvq-plugin"; break;
            case ".vrml": retval = "application/x-vrml"; break;
            case ".vrt": retval = "x-world/x-vrt"; break;
            case ".vsd": retval = "application/x-visio"; break;
            case ".vst": retval = "application/x-visio"; break;
            case ".vsw": retval = "application/x-visio"; break;
            case ".w60": retval = "application/wordperfect6.0"; break;
            case ".w61": retval = "application/wordperfect6.1"; break;
            case ".w6w": retval = "application/msword"; break;
            case ".wav": retval = "audio/wav"; break;
            case ".wb1": retval = "application/x-qpro"; break;
            case ".wbmp": retval = "image/vnd.wap.wbmp"; break;
            case ".web": retval = "application/vnd.xara"; break;
            case ".wiz": retval = "application/msword"; break;
            case ".wk1": retval = "application/x-123"; break;
            case ".wmf": retval = "windows/metafile"; break;
            case ".wml": retval = "text/vnd.wap.wml"; break;
            case ".wmlc": retval = "application/vnd.wap.wmlc"; break;
            case ".wmls": retval = "text/vnd.wap.wmlscript"; break;
            case ".wmlsc": retval = "application/vnd.wap.wmlscriptc"; break;
            case ".word": retval = "application/msword"; break;
            case ".wp": retval = "application/wordperfect"; break;
            case ".wp5": retval = "application/wordperfect"; break;
            case ".wp6": retval = "application/wordperfect"; break;
            case ".wpd": retval = "application/wordperfect"; break;
            case ".wq1": retval = "application/x-lotus"; break;
            case ".wri": retval = "application/mswrite"; break;
            case ".wrl": retval = "application/x-world"; break;
            case ".wrz": retval = "x-world/x-vrml"; break;
            case ".wsc": retval = "text/scriplet"; break;
            case ".wsrc": retval = "application/x-wais-source"; break;
            case ".wtk": retval = "application/x-wintalk"; break;
            case ".xbm": retval = "image/x-xbitmap"; break;
            case ".xdr": retval = "video/x-amt-demorun"; break;
            case ".xgz": retval = "xgl/drawing"; break;
            case ".xif": retval = "image/vnd.xiff"; break;
            case ".xl": retval = "application/excel"; break;
            case ".xla": retval = "application/vnd.ms-excel"; break;
            case ".xlb": retval = "application/vnd.ms-excel"; break;
            case ".xlc": retval = "application/vnd.ms-excel"; break;
            case ".xld": retval = "application/vnd.ms-excel"; break;
            case ".xlk": retval = "application/vnd.ms-excel"; break;
            case ".xll": retval = "application/vnd.ms-excel"; break;
            case ".xlm": retval = "application/vnd.ms-excel"; break;
            case ".xls": retval = "application/vnd.ms-excel"; break;
            case ".xlt": retval = "application/vnd.ms-excel"; break;
            case ".xlv": retval = "application/vnd.ms-excel"; break;
            case ".xlw": retval = "application/vnd.ms-excel"; break;
            case ".xm": retval = "audio/xm"; break;
            case ".xml": retval = "application/xml"; break;
            case ".xmz": retval = "xgl/movie"; break;
            case ".xpix": retval = "application/x-vnd.ls-xpix"; break;
            case ".xpm": retval = "image/xpm"; break;
            case ".x-png": retval = "image/png"; break;
            case ".xsr": retval = "video/x-amt-showrun"; break;
            case ".xwd": retval = "image/x-xwd"; break;
            case ".xyz": retval = "chemical/x-pdb"; break;
            case ".z": retval = "application/x-compressed"; break;
            case ".zip": retval = "application/zip"; break;
            case ".zoo": retval = "application/octet-stream"; break;
            case ".zsh": retval = "text/x-script.zsh"; break;
            default: retval = "application/octet-stream"; break;
        }
        return retval;
    }

    private void loadOwneridDropDown() // Added by srivatsan for owner id change
    {
        HDDatabase Hdd = new HDDatabase();
        BindControl BC = new BindControl();
        //DataSet ds = new DataSet();
        DataTable dt = null;
        try
        {

            if (Request.QueryString["PK"] == null)
            {
                p_documents_owner_id.Value = Session["user_afrowid"].ToString();
               txt_p_documents_owner_id.Text = Session["userid"].ToString();

            }
            if (Request.QueryString["PK"] != null)
            {
                if (Request.QueryString["CPY"] != null)
                {
                    p_documents_owner_id.Value = Session["user_afrowid"].ToString();
                    txt_p_documents_owner_id.Text = Session["userid"].ToString();
                }

            }
            
        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("Error : loadOwneridDropDown :" + ex.Message);
        }
        finally
        {
            Hdd = null;
            BC = null;
            dt = null;
        }


    }


    
    private void CheckForChangeOwner()  // Added by srivatsan to Check if user can change owner
    {
        try
        {
            security sec = new security();
            bool status = false;
            status = sec.getRightsForMRUObjects(HttpContext.Current.Request.QueryString["pgs_id"].ToString(), "change_owner");
            if (status == false)
            {
                imgOwnerSearch.Visible = false;
                txt_p_documents_owner_id.Enabled = false;
            }
            sec = null;
        }
        catch
        {

        }
    }

    #region loadownerid
    //private void loadOwneridDropDown() // Added by srivatsan for owner id change
    //{
    //    HDDatabase Hdd = new HDDatabase();
    //    BindControl BC = new BindControl();
    //    //DataSet ds = new DataSet();
    //    DataTable dt = null;
    //    try
    //    {
    //        string bindid = Hdd.GetColumnValue("select mem_value3 from sy_acr_mem where acr_id = 'cee69885ce44589c' and mem_id = 'owner_id'");
    //        BC.Bind(bindid, p_documents_owner_id_dd, ref dt);

    //        if (Session["user_afrowid"].ToString() == "e51e0327224a2eb9")
    //        {
    //          p_documents_owner_id_dd.Items.Add(new ListItem(Session["userid"].ToString(), Session["user_afrowid"].ToString()));
    //        }

    //        if (Request.QueryString["PK"] == null)
    //        {
    //            p_documents_owner_id_dd.SelectedValue = Session["user_afrowid"].ToString();
    //        }
    //        if (Request.QueryString["PK"] != null)
    //        {
    //            if (Request.QueryString["CPY"] != null)
    //            {
    //                p_documents_owner_id_dd.SelectedValue = Session["user_afrowid"].ToString();
    //            }

    //        }

    //    }
    //    catch (Exception ex)
    //    {
    //        LogWriter.WriteLog("Error : loadOwneridDropDown :" + ex.Message);
    //    }
    //    finally
    //    {
    //        Hdd = null;
    //        BC = null;
    //        dt = null;
    //    }


    //}
    #endregion
}
